#ifndef __MQTT_MANAGER_H__
#define __MQTT_MANAGER_H__

#include "mosquitto.h"

/**
 * @enum T_CALLBACK_TYPE
 * @brief MQTT callback type
 */
typedef enum{
    CALLBACK_TYPE_CONNECTED     = 1,
    CALLBACK_TYPE_DISCONNECTED  = 2,
    CALLBACK_TYPE_MESSAGE       = 3,
    CALLBACK_TYPE_PUBLISH       = 4,
    CALLBACK_TYPE_SUBSCRIBE     = 5,
    CALLBACK_TYPE_UNSUBSCRIBE   = 6,
    CALLBACK_TYPE_LOG           = 7
}T_CALLBACK_TYPE;

typedef int(*T_MQTT_FUNCTION_CALLBACK)(T_CALLBACK_TYPE, void *data, int data_len, int result, void *arg);

typedef struct _T_MQTT_CALLBACK{
    T_MQTT_FUNCTION_CALLBACK func_cb;
    void *data;
    int  data_len;
    int  result;
    void *arg;
    struct _T_MQTT_CALLBACK *prev;
    struct _T_MQTT_CALLBACK *next;
}T_MQTT_CALLBACK;

typedef struct _T_MQTT_MANAGER{
    struct mosquitto *mosq;
    char*  clientId;
    T_MQTT_CALLBACK *callbacks;
    T_MQTT_CALLBACK *callbackTail;
}T_MQTT_MANAGER;


extern int  mqtt_init(T_MQTT_MANAGER* manager);
extern int  mqtt_connect(T_MQTT_MANAGER* manager, const char *host, int port, const char * username, const char *password, int keepalive);
extern int  mqtt_subscribe(T_MQTT_MANAGER* manager, const char *topic, int qos);
extern int  mqtt_subscribe_multi(T_MQTT_MANAGER* manager, char* topics[], int topic_count, int qos);
extern int  mqtt_publish(T_MQTT_MANAGER* manager, const char *topic, int data_len, const void *data, int qos, bool retain);
extern int  mqtt_set_will(T_MQTT_MANAGER* manager, const char *topic, int payloadlen, const void *payload, int qos, bool retain);
extern int  mqtt_stop(T_MQTT_MANAGER* manager);
extern int  mqtt_start(T_MQTT_MANAGER* manager);
extern int  mqtt_destroy(T_MQTT_MANAGER* manager);



#endif // __MQTT_MANAGER_H__